<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>放映厅管理 - 电影院管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background-color: #f5f5f5;
            line-height: 1.6;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1rem 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .nav {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        
        .logo {
            font-size: 24px;
            font-weight: bold;
        }
        
        .nav-links {
            display: flex;
            gap: 30px;
        }
        
        .nav-links a {
            color: white;
            text-decoration: none;
            font-weight: 500;
            transition: opacity 0.3s;
        }
        
        .nav-links a:hover {
            opacity: 0.8;
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .rooms-section {
            background: white;
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        
        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 3px solid #667eea;
        }
        
        .section-title {
            font-size: 24px;
            color: #333;
        }
        
        .rooms-stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }
        
        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
        }
        
        .stat-number {
            font-size: 28px;
            font-weight: bold;
            margin-bottom: 5px;
        }
        
        .stat-label {
            font-size: 14px;
            opacity: 0.9;
        }
        
        .controls {
            display: flex;
            gap: 15px;
            margin-bottom: 20px;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .search-box {
            flex: 1;
            min-width: 200px;
            position: relative;
        }
        
        .search-box input {
            width: 100%;
            padding: 10px 40px 10px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 14px;
        }
        
        .search-box .search-icon {
            position: absolute;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            color: #666;
        }
        
        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 8px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-size: 14px;
            transition: transform 0.2s;
        }
        
        .btn:hover {
            transform: translateY(-2px);
        }
        
        .btn-success {
            background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
        }
        
        .btn-warning {
            background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
            color: #333;
        }
        
        .btn-danger {
            background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
        }
        
        .btn-sm {
            padding: 6px 12px;
            font-size: 12px;
        }
        
        .rooms-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
            gap: 20px;
        }
        
        .room-card {
            border: 1px solid #e1e1e1;
            border-radius: 10px;
            padding: 20px;
            transition: transform 0.3s, box-shadow 0.3s;
            background: white;
        }
        
        .room-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(0,0,0,0.1);
        }
        
        .room-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .room-name {
            font-size: 18px;
            font-weight: bold;
            color: #333;
        }
        
        .room-status {
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: bold;
        }
        
        .status-active {
            background: #d4edda;
            color: #155724;
        }
        
        .status-maintenance {
            background: #fff3cd;
            color: #856404;
        }
        
        .status-inactive {
            background: #f8d7da;
            color: #721c24;
        }
        
        .room-info {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-bottom: 15px;
        }
        
        .info-item {
            color: #666;
            font-size: 14px;
        }
        
        .info-label {
            font-weight: bold;
            color: #333;
        }
        
        .room-description {
            color: #666;
            font-size: 14px;
            margin-bottom: 15px;
            line-height: 1.5;
        }
        
        .room-actions {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }
        
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
        }
        
        .modal-content {
            background-color: white;
            margin: 5% auto;
            padding: 30px;
            border-radius: 15px;
            width: 90%;
            max-width: 500px;
            position: relative;
        }
        
        .close {
            position: absolute;
            right: 15px;
            top: 15px;
            font-size: 24px;
            cursor: pointer;
            color: #666;
        }
        
        .close:hover {
            color: #333;
        }
        
        .modal-title {
            font-size: 20px;
            margin-bottom: 20px;
            color: #333;
        }
        
        .form-group {
            margin-bottom: 15px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #333;
        }
        
        .form-group input,
        .form-group select,
        .form-group textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
        }
        
        .form-group textarea {
            height: 80px;
            resize: vertical;
        }
        
        .form-actions {
            display: flex;
            gap: 10px;
            justify-content: flex-end;
            margin-top: 20px;
        }
        
        .no-rooms {
            text-align: center;
            color: #666;
            font-style: italic;
            padding: 60px 20px;
        }
        
        .no-rooms-icon {
            font-size: 48px;
            margin-bottom: 20px;
            opacity: 0.5;
        }
        
        @media (max-width: 768px) {
            .rooms-grid {
                grid-template-columns: 1fr;
            }
            
            .controls {
                flex-direction: column;
                align-items: stretch;
            }
            
            .search-box {
                min-width: auto;
            }
        }
    </style>
</head>
<body>
    <header class="header">
        <nav class="nav">
            <div class="logo">🎬 管理员控制台</div>
            <div class="nav-links">
                <a href="/admin/dashboard">控制台</a>
                <a href="/admin/users">用户管理</a>
                <a href="/admin/rooms">放映厅管理</a>
                <a href="/admin/logs">系统日志</a>
            </div>
            <div class="user-info">
                <span th:text="'管理员：' + ${currentUser != null ? currentUser.username : '未登录'}">管理员</span>
                <a href="/auth/logout" class="btn btn-sm">退出登录</a>
            </div>
        </nav>
    </header>
    
    <div class="container">
        <div class="rooms-section">
            <div class="section-header">
                <h2 class="section-title">放映厅管理</h2>
                <button class="btn btn-success" onclick="openAddModal()">+ 添加放映厅</button>
            </div>
            
            <!-- 统计信息 -->
            <div class="rooms-stats">
                <div class="stat-card">
                    <div class="stat-number" th:text="${#lists.size(rooms ?: {})}">0</div>
                    <div class="stat-label">总放映厅数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" th:text="${#lists.size(rooms ?: {})}">0</div>
                    <div class="stat-label">正常使用</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number">0</div>
                    <div class="stat-label">维护中</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" th:text="${#aggregates.sum(rooms.![totalSeats])}">0</div>
                    <div class="stat-label">总座位数</div>
                </div>
            </div>
            
            <!-- 控制区域 -->
            <div class="controls">
                <div class="search-box">
                    <input type="text" id="searchInput" placeholder="搜索放映厅名称...">
                    <span class="search-icon">🔍</span>
                </div>
                <select id="statusFilter">
                    <option value="">全部状态</option>
                    <option value="active">正常使用</option>
                    <option value="maintenance">维护中</option>
                    <option value="inactive">停用</option>
                </select>
            </div>
            
            <!-- 放映厅列表 -->
            <div class="rooms-grid" th:if="${rooms != null and !rooms.empty}">
                <div class="room-card" th:each="room : ${rooms}">
                    <div class="room-header">
                        <div class="room-name" th:text="${room.name}">放映厅名称</div>
                        <div class="room-status status-active">正常使用</div>
                    </div>
                    
                    <div class="room-info">
                        <div class="info-item">
                            <span class="info-label">座位数：</span>
                            <span th:text="${room.totalSeats}">座位数</span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">类型：</span>
                            <span th:text="${room.roomType ?: '标准厅'}">标准厅</span>
                        </div>
                        <div class="info-item">
                            <span class="info-label">设备：</span>
                            <span th:text="${room.equipment ?: '标准设备'}">标准设备</span>
                        </div>
                    </div>
                    
                    <div class="room-description" th:text="${room.description ?: '放映厅设施完善，环境舒适'}">放映厅设施完善，环境舒适</div>
                    
                    <div class="room-actions">
                        <button class="btn btn-warning btn-sm" 
                                th:data-room-id="${room.id}"
                                onclick="editRoom(this.dataset.roomId)">编辑</button>
                        <a th:href="@{/admin/room-screenings/{id}(id=${room.id})}" class="btn btn-sm">查看场次</a>
                        <button class="btn btn-danger btn-sm" 
                                th:data-room-id="${room.id}"
                                onclick="deleteRoom(this.dataset.roomId)">删除</button>
                    </div>
                </div>
            </div>
            
            <!-- 无数据提示 -->
            <div th:if="${rooms == null or rooms.empty}" class="no-rooms">
                <div class="no-rooms-icon">🏢</div>
                <h3>暂无放映厅</h3>
                <p>还没有添加任何放映厅，点击上方按钮添加第一个放映厅吧！</p>
            </div>
        </div>
    </div>
    
    <!-- 添加/编辑放映厅模态框 -->
    <div id="roomModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal()">&times;</span>
            <h3 class="modal-title" id="modalTitle">添加放映厅</h3>
            <form id="roomForm" method="post">
                <input type="hidden" id="roomId" name="roomId">
                
                <div class="form-group">
                    <label for="roomName">放映厅名称 *</label>
                    <input type="text" id="roomName" name="name" required>
                </div>
                
                <div class="form-group">
                    <label for="seatCount">座位数 *</label>
                    <input type="number" id="seatCount" name="seatCount" min="1" required>
                </div>
                
                <div class="form-group">
                    <label for="roomType">放映厅类型</label>
                    <select id="roomType" name="roomType">
                        <option value="标准厅">标准厅</option>
                        <option value="IMAX厅">IMAX厅</option>
                        <option value="4D厅">4D厅</option>
                        <option value="VIP厅">VIP厅</option>
                        <option value="杜比厅">杜比厅</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label for="equipment">设备配置</label>
                    <input type="text" id="equipment" name="equipment" placeholder="如：数字投影、环绕音响等">
                </div>
                
                <div class="form-group">
                    <label for="description">描述信息</label>
                    <textarea id="description" name="description" placeholder="放映厅的详细描述..."></textarea>
                </div>
                
                <div class="form-actions">
                    <button type="button" class="btn" onclick="closeModal()">取消</button>
                    <button type="submit" class="btn btn-success">保存</button>
                </div>
            </form>
        </div>
    </div>
    
    <script>
        // 搜索功能
        document.getElementById('searchInput').addEventListener('input', function() {
            filterRooms();
        });
        
        document.getElementById('statusFilter').addEventListener('change', function() {
            filterRooms();
        });
        
        function filterRooms() {
            const searchTerm = document.getElementById('searchInput').value.toLowerCase();
            const statusFilter = document.getElementById('statusFilter').value;
            const roomCards = document.querySelectorAll('.room-card');
            
            roomCards.forEach(card => {
                const roomName = card.querySelector('.room-name').textContent.toLowerCase();
                const roomStatus = card.querySelector('.room-status');
                
                let showBySearch = roomName.includes(searchTerm);
                let showByStatus = true;
                
                if (statusFilter) {
                    showByStatus = roomStatus.classList.contains('status-' + statusFilter);
                }
                
                card.style.display = (showBySearch && showByStatus) ? 'block' : 'none';
            });
        }
        
        // 模态框操作
        function openAddModal() {
            document.getElementById('modalTitle').textContent = '添加放映厅';
            document.getElementById('roomForm').action = '/admin/rooms/create';
            document.getElementById('roomForm').reset();
            document.getElementById('roomId').value = '';
            document.getElementById('roomModal').style.display = 'block';
        }
        
        function editRoom(roomId) {
            document.getElementById('modalTitle').textContent = '编辑放映厅';
            document.getElementById('roomForm').action = '/admin/rooms/edit';
            document.getElementById('roomId').value = roomId;
            
            // 通过AJAX获取放映厅详情并填充表单
            fetch('/admin/rooms/get/' + roomId)
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        document.getElementById('roomName').value = data.name;
                        document.getElementById('seatCount').value = data.seatCount;
                        document.getElementById('roomType').value = data.roomType || '标准厅';
                        document.getElementById('equipment').value = data.equipment || '';
                        document.getElementById('description').value = data.description || '';
                        document.getElementById('roomModal').style.display = 'block';
                    } else {
                        alert('获取放映厅信息失败：' + data.message);
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('获取放映厅信息失败，请重试');
                });
        }
        
        function closeModal() {
            document.getElementById('roomModal').style.display = 'none';
        }
        
        function deleteRoom(roomId) {
            if (confirm('确定要删除这个放映厅吗？删除后将无法恢复！')) {
                // 发送删除请求
                window.location.href = '/admin/rooms/delete/' + roomId;
            }
        }
        
        // 点击模态框外部关闭
        window.onclick = function(event) {
            const modal = document.getElementById('roomModal');
            if (event.target === modal) {
                closeModal();
            }
        }
    </script>
</body>
</html>